﻿--[[
   @brief    model for friend list ui
   @author   vincentlao
   @version  1.0
   @date     2015-07-09
--]]

-- all the index is zero based

chat_vlist_model =
{
    current_selected_ = nil;
    b_discussion_cllapsed_ = true;--记录讨论组是否收起。
    b_group_cllapsed_ = false;--记录群组分组是否收起。
    cache_friend_info = {};

    virtual_node_id_to_group_info = {};
    current_selected_group_id = "";
    current_selected_group_id = "";

    NODE_TYPE_DISCUSSION_TITLE = 1;
    NODE_TYPE_DISCUSSION_NODE = 2;
    NODE_TYPE_GROUP_TITLE = 3;
    NODE_TYPE_GROUP_NODE = 4;
    NODE_TYPE_NO_DISCUSS_TIPS = 5;
    NODE_TYPE_NO_GROUP_TIPS = 6;

    get_user_level_done = false;
    social_user_level = 0;
    max_mode_msg_list_tips_id = 0;
    max_mode_contact_list_tips_id = 0;
    min_mode_msg_list_tips_id = 0;
    min_mode_contact_list_tips_id = 0;

    get_group_list_done = false;
    mainframe_mode = 0; --默认大界面模式

    already_apply_join_group_ids = {};
    join_group_btn_id_to_group_id = {};

    NODE_HEIGHT = 60;

    get_group_count = function()
        if chat_vlist_model.b_group_cllapsed_ == true then
            return 0;
        end;
        --return friend_list_model.get_friend_count();
        return contact_message_list_model.get_chat_count();
    end;

    get_group_info_by_index = function(index)
        --return friend_list_model.get_friend_info_by_index(index + 1);-- index是1开始的，不是zero based
        return contact_message_list_model.get_banner_info_by_index(index + 1);
    end;

    init = function()
        ierd_tgp.tpf_ui.Log("[chat_vlist_model]init");
    end;

    uninit = function()
        ierd_tgp.tpf_ui.Log("[chat_vlist_model]uninit");
    end;

    get_item_info = function(index)
        --MessageBox(index);
        local info = {};
        info['name'] = tostring(index - 0);
        group_info = chat_vlist_model.get_group_info_by_index(index - 0);
        --MessageBox(base_utility.table_to_json(group_info));
        if group_info ~= nil then
            info['group_info'] = group_info
            return chat_vlist_model.NODE_TYPE_GROUP_NODE, "social\\session_node.tpf", info, chat_vlist_model.NODE_HEIGHT;
        end;

    end;

    get_total_item_height = function()
        local height = 0;
        local group_count = chat_vlist_model.get_group_count();
        height = height + chat_vlist_model.NODE_HEIGHT * group_count; --群组节点

        return height;
    end;

    first_visible_item_index = function(scrollbar_pos)
        local height = 0;
        local i = 0;
        local max_node = chat_vlist_model.get_group_count() - 1;
        for i = 0, max_node do
            height = height + chat_vlist_model.NODE_HEIGHT;

            if height > scrollbar_pos then
                return i;
            end;
        end;
        MessageBox(scrollbar_pos);
        return i;
    end;

    offset_of_first_visible_item_index = function(first_visible_index)
        local offset = 0;
        for i = 0, first_visible_index - 1 do
            offset = offset + chat_vlist_model.NODE_HEIGHT;
        end;
        return offset;
    end;

    clicked_treenode = function()
        chat_vlist_model.b_discussion_cllapsed_ = not chat_vlist_model.b_discussion_cllapsed_;
    end;
    clicked_grouptreenode = function()
        chat_vlist_model.b_group_cllapsed_ = not chat_vlist_model.b_group_cllapsed_;
    end;
};

chat_vlist_model.init();
